
// Table A.2

use    "${dataout}MainDataset" , clear

keep if couple==1
keep if year>=2008

* Setting panel structure for xtsum
xtset familienr_num year

*-----------------------------------------------------
/*Residualized: absorb grunnkrets*year FE. Include 3 years (2015-2017)*/
*-----------------------------------------------------

local xvarlist toll_fam_mean ptl_fam_km_mean   /* toll_fam_mean ptl_fam_km_mean  BEV_fam_yes*/
foreach x in `xvarlist' {
capt drop res_`x'
reghdfe `x' if year>=2015 & year<=2017 , absorb(i.year#i.grkrets_num i.year#i.grk_bed1_num i.year#i.grk_bed2_num)  residuals(res_`x') 
sum `x'  if e(sample)==1
return list
dis "`r(mean)'"
capt gen resNY1517_`x'=.
replace resNY1517_`x'=  res_`x' + `r(mean)'
capt drop res_`x'
}

*-----------------------------------------------------
/*Residualized: absorb grunnkrets*year FE. Include 10 years (2008-2017)*/
*-----------------------------------------------------

local xvarlist toll_fam_mean ptl_fam_km_mean  
foreach x in `xvarlist' {
capt drop res_`x'
reghdfe `x' if year>=2008 & year<=2017 , absorb(i.year#i.grkrets_num i.year#i.grk_bed1_num i.year#i.grk_bed2_num)  residuals(res_`x') 
sum `x'  if e(sample)==1
return list
dis "`r(mean)'"
capt gen resNY0817_`x'=.
replace resNY0817_`x'=  res_`x' + `r(mean)'
capt drop res_`x'
}

*-- within: over time for each household
*-- between: cross-section

* The output produced below is exactly the same as the numbers in the tables:

*-----------------------------------------------------
/* Table A2: Panel data variation in road toll (NOK) */
*-----------------------------------------------------

local xvarlist  toll_fam_mean
foreach x in `xvarlist' {
	* Period 2015-2017, raw data:
	xtsum `x'  if year>=2015 & year<=2017
	* Period 2015-2017, residualized data:
	xtsum resNY1517_`x'  if year>=2015 & year<=2017

	* Period 2008-2017, raw data:
	xtsum `x'  if year>=2008 & year<=2017
	* Period 2008-2017, residualized data:
	xtsum resNY0817_`x'  if year>=2008 & year<=2017
}

*-----------------------------------------------------
/* Table A3: Panel data variation in bus lane distance (km) */
*-----------------------------------------------------

local xvarlist  ptl_fam_km_mean
foreach x in `xvarlist' {
	* Period 2015-2017, raw data:
	xtsum `x'  if year>=2015 & year<=2017
	* Period 2015-2017, residualized data:
	xtsum resNY1517_`x'  if year>=2015 & year<=2017

	* Period 2008-2017, raw data:
	xtsum `x'  if year>=2008 & year<=2017
	* Period 2008-2017, residualized data:
	xtsum resNY0817_`x'  if year>=2008 & year<=2017
}

